package com.gdth.widget.listview.refresh;

import com.gdth.R;

import android.content.Context;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class HerderView extends View{
	private Context mContext;
	
	public TextView tip;
	public TextView lastUpdate;
	public ImageView arrow;
	public ProgressBar refreshing;
	
	private int layout_header = R.layout.aron_listview_header;
	
	public HerderView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		
		this.mContext = context;
		
		init();
	}
	
	public void init(){
		inflate(this.mContext, layout_header, null);
		
		arrow = (ImageView) this.findViewById(R.id.arrow);
		tip = (TextView) this.findViewById(R.id.tip);
		lastUpdate = (TextView) this.findViewById(R.id.lastUpdate);
		refreshing = (ProgressBar) this.findViewById(R.id.refreshing);
	}
	
	public void setTipText(int id){
		tip.setText(id);
	}
	
	public void setLastUpdateTime(){
		lastUpdate.setText(this.getContext().getString(R.string.lastUpdateTime, ListViewUtil.getCurrentTime()));
	}
	
	public void setViewVisibility(View view, int type){
		view.setVisibility(type);
	}
	
	public void topPadding(int topPadding) {
		this.setPadding(getPaddingLeft(), topPadding, getPaddingRight(), getPaddingBottom());
		invalidate();
	}
	
	/**
	 * 设置正常状态
	 */
	public void setStateByNone(){
		tip.setText(R.string.pull_to_refresh);
		refreshing.setVisibility(View.GONE);

		arrow.clearAnimation();
		arrow.setImageResource(R.drawable.pull_to_refresh_up);
	}
	
	/**
	 * 设置下拉样式
	 */
	public void setStateByPull(RotateAnimation arg0){
		arrow.setVisibility(View.VISIBLE);
		tip.setVisibility(View.VISIBLE);
		lastUpdate.setVisibility(View.VISIBLE);
		refreshing.setVisibility(View.GONE);
		tip.setText(R.string.pull_to_refresh);
		arrow.clearAnimation();
		arrow.setAnimation(arg0);
	}
	
	/**
	 * 设置刷新样式
	 */
	public void setStateByRefresh(RotateAnimation arg0){
		arrow.setVisibility(View.VISIBLE);
		tip.setVisibility(View.VISIBLE);
		lastUpdate.setVisibility(View.VISIBLE);
		refreshing.setVisibility(View.GONE);
		tip.setText(R.string.pull_to_refresh);
		tip.setText(R.string.release_to_refresh);
		arrow.clearAnimation();
		arrow.setAnimation(arg0);
	}
	
	/**
	 * 设置正在刷新样式
	 */
	public void setStateByRefreshing(){
		refreshing.setVisibility(View.VISIBLE);
		arrow.clearAnimation();
		arrow.setVisibility(View.GONE);
		tip.setVisibility(View.GONE);
		lastUpdate.setVisibility(View.GONE);
	}
}
